﻿<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:ShoppingList"
    xmlns:my="clr-namespace:System;assembly=mscorlib" xmlns:ic="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
    x:Class="ShoppingList.MainPage"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"
    d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded" DataContext="{Binding}">

    <phone:PhoneApplicationPage.Resources>
        <local:MainViewModel x:Key="MainViewModelDataSource" d:IsDataSource="True"/>
        <my:String x:Key="help">help</my:String>
        <Style x:Key="TransferButtonStyle" TargetType="Button">
            <Style.Setters>
                <Setter Property="Width" Value="60"></Setter>
                <Setter Property="Height" Value="60"></Setter>
                <Setter Property="Margin" Value="0,-5,0,-10"></Setter>
                <Setter Property="BorderThickness" Value="0"></Setter>
                <Setter Property="HorizontalAlignment" Value="Right"></Setter>
                <Setter Property="VerticalAlignment" Value="Center"></Setter>
                <Setter Property="Grid.Column" Value="2"></Setter>
            </Style.Setters>
        </Style>
        <Style x:Key="TransferButtonPathStyle" TargetType="Path">
            <Setter Property="Width" Value="30"></Setter>
            <Setter Property="Height" Value="25"></Setter>
            <Setter Property="Stroke" Value="{StaticResource PhoneForegroundBrush}"></Setter>
            <Setter Property="Stretch" Value="Fill"></Setter>
            <Setter Property="Fill" Value="{StaticResource PhoneBackgroundBrush}"></Setter>
            <Setter Property="StrokeThickness" Value="2"></Setter>
            <Setter Property="Margin" Value="-10,-10,-10,-10"></Setter>
        </Style>
        <my:String x:Key="sendviaemail">send via email</my:String>
    </phone:PhoneApplicationPage.Resources>

    <!--Sample code showing usage of ApplicationBar-->
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="btn_sendviaemail" Text="{StaticResource sendviaemail}" Click="btn_sendviaemail_Click" />
                <shell:ApplicationBarMenuItem x:Name="btn_sortitemsbyname" Text="sort items by name" Click="btn_sortitemsbyname_Click" />
                <shell:ApplicationBarMenuItem x:Name="btn_sortitemsbyprice" Text="sort items by price" Click="btn_sortitemsbyprice_Click" />
                <shell:ApplicationBarMenuItem x:Name="btn_sortitemsbyunitprice" Text="sort items by unit price" Click="btn_sortitemsbyunitprice_Click" />
                <shell:ApplicationBarMenuItem Text="{StaticResource help}" Click="ApplicationBarMenuItemHelp_Click" />
            </shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarIconButton IconUri="/Images/white/add.png" Text="Add item" Click="ApplicationBarAddItemButton_Click" />
            <shell:ApplicationBarIconButton IconUri="/Images/white/edit.png" Text="Edit item" Click="ApplicationBarEditItemButton_Click" IsEnabled="False" />
            <shell:ApplicationBarIconButton IconUri="/Images/white/delete.png" Text="Delete" Click="ApplicationBarDeleteButton_Click" IsEnabled="False"/>
            <shell:ApplicationBarIconButton IconUri="/Images/white/appbar.manage.rest.png" Text="Lists" Click="ApplicationBarListsIconButton_Click"/>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

    <phone:PhoneApplicationPage.FontFamily>
        <StaticResource ResourceKey="PhoneFontFamilyNormal"/>
    </phone:PhoneApplicationPage.FontFamily>
    <phone:PhoneApplicationPage.FontSize>
        <StaticResource ResourceKey="PhoneFontSizeNormal"/>
    </phone:PhoneApplicationPage.FontSize>
    <phone:PhoneApplicationPage.Foreground>
        <StaticResource ResourceKey="PhoneForegroundBrush"/>
    </phone:PhoneApplicationPage.Foreground>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <TextBlock x:Name="ListName" Text="{StaticResource AppTitle}"/>
        <!--Pivot Control-->
        <controls:Pivot Name="itemspivot"  Title="{Binding CurrentList.Name}" Margin="1,10,-1,0"
                         DisplayMemberPath="{Binding}"
                          SelectionChanged="Pivot_SelectionChanged" ItemsSource="{Binding}" DataContext="{Binding}">
            <!--Pivot item one-->
            <controls:PivotItem Name="onlist" Header="on list" DataContext="{Binding CurrentList}" >
                <!--Double line list with text wrapping-->
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition Height="30" />
                    </Grid.RowDefinitions>
                    <ListBox x:Name="FirstListBox" Margin="0,0,-10,0"
                         ItemsSource="{Binding}" Grid.Row="0"
                         DataContext="{Binding ItemsOnList}" Visibility="Visible"
                         MouseLeftButtonDown="ListBox_MouseLeftButtonDown"
                         SelectionChanged="listItemSelected" ItemContainerStyle="{StaticResource ListBoxItemStyle1}"
                             BorderBrush="{StaticResource PhoneBorderBrush}" BorderThickness="0,0,0,1">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,5">
                                    <StackPanel Margin="0,0,0,0" Grid.Column="0" VerticalAlignment="Center"
                                            MouseLeftButtonDown="StackPanel_MouseLeftButtonDown"
                                            Visibility="Visible" Width="350">
                                        <TextBlock Text="{Binding Path=ItemName}" Visibility="Visible"
                                               TextWrapping="Wrap" ToolTipService.ToolTip="{Binding Path=Comment}"/>
                                        <TextBlock Text="{Binding Comment}" x:Name="Comment"
                                               TextWrapping="Wrap" Style="{StaticResource PhoneTextSmallStyle}" Visibility="{Binding Path=Selected, Converter={StaticResource BooleanToVisibilityConverter}}" />
                                    </StackPanel>
                                    <StackPanel Orientation="Vertical" VerticalAlignment="Center"
                                                Grid.Column="1" Width="60">
                                        <TextBlock Text="{Binding Amount}"  TextWrapping="Wrap"
                                           VerticalAlignment="Center" HorizontalAlignment="Right"
                                                   FontWeight="Bold" FontSize="22"
                                                   Foreground="{StaticResource PhoneContrastBackgroundBrush}" />
                                        <TextBlock Text="{Binding Path=Price, Converter={StaticResource PriceConverter}}" x:Name="Sum"
                                           VerticalAlignment="Center" HorizontalAlignment="Right"
                                               TextWrapping="Wrap" Foreground="{StaticResource PhoneSubtleBrush}"
                                                   Visibility="{Binding Path=Selected, Converter={StaticResource BooleanToVisibilityConverter}}"
                                                   FontSize="16"/>
                                        <TextBlock Text="{Binding Sum}" x:Name="PriceInfo"
                                           VerticalAlignment="Center" HorizontalAlignment="Right"
                                               TextWrapping="Wrap" Visibility="{Binding Path=ItemSumVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
                                                   Foreground="{StaticResource PhoneSubtleBrush}"
                                                   FontSize="14" />
                                    </StackPanel>
                                    <Button x:Name="AddItem"  Style="{StaticResource TransferButtonStyle}" Click="SwitchItem_Click">
                                        <Path x:Name="Check_1034" Style="{StaticResource TransferButtonPathStyle}"
                                          Canvas.Left="770" Canvas.Top="388.332" Stretch="Fill" Data="F1 M 785,390.453L 782.878,388.332L 775.196,396.012L 772.122,392.937L 770,395.058L 775.192,400.251L 785,390.453 Z "/>
                                    </Button>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <StackPanel Orientation="Horizontal"  Grid.Row="1" HorizontalAlignment="Right">
                        <TextBlock Text="Total" Style="{StaticResource PhoneTextAccentStyle}"></TextBlock>
                        <TextBlock Text="{Binding Path=ListSum, Converter={StaticResource PriceConverter}}"  Width="370" DataContext="{Binding}" HorizontalAlignment="Right" FontWeight="Bold" TextAlignment="Right" Style="{StaticResource PhoneTextAccentStyle}"></TextBlock>
                    </StackPanel>
                </Grid>
            </controls:PivotItem>
            <!--Pivot item two-->
            <controls:PivotItem Name="incart" Header="in cart" DataContext="{Binding CurrentList}">
                <!--Triple line list no text wrapping-->
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition Height="30" />
                    </Grid.RowDefinitions>
                    <ListBox x:Name="SecondListBox" Margin="0,0,-10,0"
                         ItemsSource="{Binding}" Grid.Row="0"
                         DataContext="{Binding ItemsInCart}"
                         MouseLeftButtonDown="ListBox_MouseLeftButtonDown"
                         SelectionChanged="listItemSelected"
                         ItemContainerStyle="{StaticResource ListBoxItemStyle1}"
                         BorderBrush="{StaticResource PhoneBorderBrush}" BorderThickness="0,0,0,1">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,5">
                                    <StackPanel Margin="0,0,0,0" Grid.Column="0"
                                                VerticalAlignment="Center"
                                                MouseLeftButtonDown="StackPanel_MouseLeftButtonDown"
                                                Width="350">
                                        <TextBlock Text="{Binding ItemName}"
                                               TextWrapping="Wrap"/>
                                        <TextBlock Text="{Binding Comment}" x:Name="Comment"
                                               TextWrapping="Wrap" Style="{StaticResource PhoneTextSmallStyle}"
                                                   Visibility="{Binding Path=Selected,
                                            Converter={StaticResource BooleanToVisibilityConverter}}" />
                                    </StackPanel>
                                    <StackPanel Orientation="Vertical" VerticalAlignment="Center"
                                                Grid.Column="1" Width="60">
                                        <TextBlock Text="{Binding Amount}"  TextWrapping="Wrap"
                                           VerticalAlignment="Center" HorizontalAlignment="Right"
                                                   FontWeight="Bold" FontSize="22"
                                                   Foreground="{StaticResource PhoneContrastBackgroundBrush}" />
                                        <TextBlock Text="{Binding Path=Price, Converter={StaticResource PriceConverter}}" x:Name="Sum"
                                           VerticalAlignment="Center" HorizontalAlignment="Right"
                                               TextWrapping="Wrap" Foreground="{StaticResource PhoneSubtleBrush}"
                                                   Visibility="{Binding Path=Selected, Converter={StaticResource BooleanToVisibilityConverter}}"
                                                   FontSize="16"/>
                                        <TextBlock Text="{Binding Sum}" x:Name="PriceInfo"
                                           VerticalAlignment="Center" HorizontalAlignment="Right"
                                               TextWrapping="Wrap" Visibility="{Binding Path=ItemSumVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
                                                   Foreground="{StaticResource PhoneSubtleBrush}"
                                                   FontSize="14" />
                                    </StackPanel>
                                    <Button x:Name="RemoveItem" Style="{StaticResource TransferButtonStyle}" Click="SwitchItem_Click">
                                        <Path x:Name="Back_1074" Style="{StaticResource TransferButtonPathStyle}"
                                              Canvas.Left="528.487" Canvas.Top="421.5"
                                              Data="F1 M 533.664,424.541L 533.664,421.5L 528.487,426.676L 533.664,431.853L 533.664,428.354C 541.187,428.479 543.699,434.023 537.707,436.097C 539.349,436.097 541.235,434.765 542,434C 545.232,430.768 542.712,424.656 533.664,424.541 Z " />
                                    </Button>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <StackPanel Orientation="Horizontal"  Grid.Row="1" HorizontalAlignment="Right">
                        <TextBlock Text="Total" Style="{StaticResource PhoneTextAccentStyle}"></TextBlock>
                        <TextBlock Text="{Binding Path=CartSum, Converter={StaticResource PriceConverter}}"  Width="370" DataContext="{Binding}" HorizontalAlignment="Right" FontWeight="Bold" TextAlignment="Right" Style="{StaticResource PhoneTextAccentStyle}"></TextBlock>
                    </StackPanel>
                </Grid>
            </controls:PivotItem>
        </controls:Pivot>
    </Grid>
</phone:PhoneApplicationPage>